﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TimelineNet.Library;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack) {
            

            this.HeightTextBox.Text = Timeline2.Height.Value.ToString();
            this.WidthTextBox.Text = Timeline2.Width.Value.ToString();
            this.BubbleHeightTextBox.Text = Timeline2.BubbleHeight.ToString();
            this.BubbleWidthTextBox.Text = Timeline2.BubbleWidth.ToString();
            this.DataUrlTextbox.Text = Timeline2.DataUrl;
            //VerticalCheckBox.Checked = Timeline2.Vertical;
            foreach(string name in Enum.GetNames(typeof(TimelineNet.DataSourceTypes))) {
                ListItem li = new ListItem(name);
                li.Value = name;
                if(name == Timeline2.DataSourceType.ToString()) li.Selected = true;
                DataSourceDropDown.Items.Add(li);
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e) {
        Timeline2.Height = new Unit(this.HeightTextBox.Text);
        Timeline2.Width = new Unit(this.WidthTextBox.Text + "%");
        Timeline2.BubbleHeight = ParseString(this.BubbleHeightTextBox.Text, Timeline2.BubbleHeight);
        Timeline2.BubbleWidth = ParseString(this.BubbleWidthTextBox.Text, Timeline2.BubbleWidth);
        Timeline2.DataUrl = this.DataUrlTextbox.Text;
        string name = DataSourceDropDown.SelectedValue;
        //Timeline2.Vertical=VerticalCheckBox.Checked;
        Timeline2.DataSourceType = (TimelineNet.DataSourceTypes)System.Enum.Parse(typeof(TimelineNet.DataSourceTypes), name);
    
    }
    private int ParseString(string value, int DefaultValue) {       
        if(value != null && value.Trim() != "") {
            int v;
            if(int.TryParse(value, out v)) return v;            
        }
        return DefaultValue;
    }
    private double ParseString(string value, double DefaultValue) {
        if(value != null && value.Trim() != "") {
            double v;
            if(double.TryParse(value, out v)) return v;
        }
        return DefaultValue;
    }
}
